import { useEffect, useState } from "react"

import axios from "axios"

export function MyEffect({show}) {
    const [num, setNum] = useState(0)

    const [count, setCount] = useState(0)

    const [list, setList] = useState([])
    useEffect(() => {
        // console.log(222)
        // async function getList(){
        //     let result = await fetch("http://geek.itheima.net/v1_0/channels")
        //     let res = await result.json()
        //     setList(res.data.channels)
        // }


        // function getList() {

        //     axios.get("http://geek.itheima.net/v1_0/channels").then
        //         (function (res) {
        //             setList(res.data.data.channels)
        //         })
        // }
        // getList()

        let time =  setInterval(()=>{
            console.log("我是定时器")
        },1000)

        console.log(111)


        return ()=>{
            clearInterval(time)
        }
    }, [count])


    return (
        <div>
                副作用函数
            <button onClick={() => setNum(num + 1)}>num:{num}</button>

            <button onClick={() => setCount(count + 1)}>count:{count}</button>


            <ul>
                {
                    list.map(v => <li key={v.id}>{v.name}</li>)
                }
            </ul>
        </div>
    )
}

